// import {Actionsheet, TransferDom} from 'vux'
import Actionsheet from 'vux/src/components/actionsheet/index.vue'
import TransferDom from 'vux/src/directives/transfer-dom/index'
import CONSTANT from '@/common/constants.js'
import http from '@/common/http.js'
export default {
  name: 'donation',
  components: {
    Actionsheet
  },
  directives: {
    TransferDom
  },
  data () {
    return {
      show: true,
      showcancel: false,
      form: '',
      id: '',
      requestSecret: ''
    }
  },
  mounted () {
    console.log(this)
    this.id = this.$route.query.id
    // location.href = 'http://etzx.hztangong.com/zfb_alipay_zx?id=1'
    // 判断当前环境是否为微信内置浏览器
    var ua = navigator.userAgent.toLowerCase()
    var isWeixin = ua.indexOf('micromessenger') != -1
    if (!isWeixin) {
      console.log(this.id)
      this.requestSecret = window.sessionStorage.getItem('requestSecret')
      http.post('http://etzx.hztangong.com/zfb_alipay_zx', {'appKey': '8a074cba6071d23b016071df85180000', 'requestSecret': this.requestSecret, 'type': '21', product_id: this.product_id, openid: this.openid, callBackUrl: encodeURI(CONSTANT.RECEIPT_ACHIEVE), 'orderInfo': '{"count": 1,"product_id":"' + this.product_id + '", "product_name": "' + this.theme + '","product_detail": "' + this.eventAbstract + '","price":' + this.money + '}'}, (res) => {
        console.log(res)
        var data = res.obj.form
        console.log(data)
        // document.getElementById('alipayTips').innerHTML = data
        document.body.innerHTML = data
        // 通过innerHTML添加的script代码不会自动执行，需要我们手动来执行
        var scripts = document.body.getElementsByTagName('script')
        for (var i = 0; i < scripts.length; i++) { // 一段一段执行script
          eval(scripts[i].innerHTML)
        }
      })
    }
  },
  methods: {
    comeback () {
      window.history.go(-1)
    },
    comebackTwo () {
      window.history.go(-1)
    }
  }
}
